<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主表id" prop="excelId">
        <el-input v-model="queryParams.excelId" placeholder="请输入主表id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="公称直径(mm)" prop="gongczj">
        <el-input v-model="queryParams.gongczj" placeholder="请输入公称直径(mm)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="公称截面积(mm²)" prop="gongcjmj">
        <el-input v-model="queryParams.gongcjmj" placeholder="请输入公称截面积(mm²)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="屈服荷载(kN)" prop="qvfhz">
        <el-input v-model="queryParams.qvfhz" placeholder="请输入屈服荷载(kN)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="屈服强度(MPa)" prop="qvfqd">
        <el-input v-model="queryParams.qvfqd" placeholder="请输入屈服强度(MPa)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="极限荷载(kN)" prop="jixhz">
        <el-input v-model="queryParams.jixhz" placeholder="请输入极限荷载(kN)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="抗拉强度(MPa)" prop="kanglqd">
        <el-input v-model="queryParams.kanglqd" placeholder="请输入抗拉强度(MPa)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="原始标距(mm)" prop="yuanszb">
        <el-input v-model="queryParams.yuanszb" placeholder="请输入原始标距(mm)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="断后标距(mm)" prop="duanhbj">
        <el-input v-model="queryParams.duanhbj" placeholder="请输入断后标距(mm)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="断后伸长率(%)" prop="duanhscl">
        <el-input v-model="queryParams.duanhscl" placeholder="请输入断后伸长率(%)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大力标距(mm)" prop="zuidlbj">
        <el-input v-model="queryParams.zuidlbj" placeholder="请输入最大力标距(mm)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大力断后标距(mm)" prop="zuidldhbj">
        <el-input v-model="queryParams.zuidldhbj" placeholder="请输入最大力断后标距(mm)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大力总延伸率(%)" prop="zuidlzysl">
        <el-input v-model="queryParams.zuidlzysl" placeholder="请输入最大力总延伸率(%)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="强屈比" prop="qiangqb">
        <el-input v-model="queryParams.qiangqb" placeholder="请输入强屈比" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="屈屈比" prop="qvqb">
        <el-input v-model="queryParams.qvqb" placeholder="请输入屈屈比" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="断裂特征" prop="daunltz">
        <el-input v-model="queryParams.daunltz" placeholder="请输入断裂特征" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gcqfqdklqddhsclzdlzysljlbBsDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label align="center" prop="id" v-if="true" />
      <el-table-column label="主表id" align="center" prop="excelId" />
      <el-table-column label="公称直径(mm)" align="center" prop="gongczj" />
      <el-table-column label="公称截面积(mm²)" align="center" prop="gongcjmj" />
      <el-table-column label="屈服荷载(kN)" align="center" prop="qvfhz" />
      <el-table-column label="屈服强度(MPa)" align="center" prop="qvfqd" />
      <el-table-column label="极限荷载(kN)" align="center" prop="jixhz" />
      <el-table-column label="抗拉强度(MPa)" align="center" prop="kanglqd" />
      <el-table-column label="原始标距(mm)" align="center" prop="yuanszb" />
      <el-table-column label="断后标距(mm)" align="center" prop="duanhbj" />
      <el-table-column label="断后伸长率(%)" align="center" prop="duanhscl" />
      <el-table-column label="最大力标距(mm)" align="center" prop="zuidlbj" />
      <el-table-column label="最大力断后标距(mm)" align="center" prop="zuidldhbj" />
      <el-table-column label="最大力总延伸率(%)" align="center" prop="zuidlzysl" />
      <el-table-column label="强屈比" align="center" prop="qiangqb" />
      <el-table-column label="屈屈比" align="center" prop="qvqb" />
      <el-table-column label="断裂特征" align="center" prop="daunltz" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['report_gc:gcqfqdklqddhsclzdlzysljlbBsDetail:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主表id" prop="excelId">
          <el-input v-model="form.excelId" placeholder="请输入主表id" />
        </el-form-item>
        <el-form-item label="公称直径(mm)" prop="gongczj">
          <el-input v-model="form.gongczj" placeholder="请输入公称直径(mm)" />
        </el-form-item>
        <el-form-item label="公称截面积(mm²)" prop="gongcjmj">
          <el-input v-model="form.gongcjmj" placeholder="请输入公称截面积(mm²)" />
        </el-form-item>
        <el-form-item label="屈服荷载(kN)" prop="qvfhz">
          <el-input v-model="form.qvfhz" placeholder="请输入屈服荷载(kN)" />
        </el-form-item>
        <el-form-item label="屈服强度(MPa)" prop="qvfqd">
          <el-input v-model="form.qvfqd" placeholder="请输入屈服强度(MPa)" />
        </el-form-item>
        <el-form-item label="极限荷载(kN)" prop="jixhz">
          <el-input v-model="form.jixhz" placeholder="请输入极限荷载(kN)" />
        </el-form-item>
        <el-form-item label="抗拉强度(MPa)" prop="kanglqd">
          <el-input v-model="form.kanglqd" placeholder="请输入抗拉强度(MPa)" />
        </el-form-item>
        <el-form-item label="原始标距(mm)" prop="yuanszb">
          <el-input v-model="form.yuanszb" placeholder="请输入原始标距(mm)" />
        </el-form-item>
        <el-form-item label="断后标距(mm)" prop="duanhbj">
          <el-input v-model="form.duanhbj" placeholder="请输入断后标距(mm)" />
        </el-form-item>
        <el-form-item label="断后伸长率(%)" prop="duanhscl">
          <el-input v-model="form.duanhscl" placeholder="请输入断后伸长率(%)" />
        </el-form-item>
        <el-form-item label="最大力标距(mm)" prop="zuidlbj">
          <el-input v-model="form.zuidlbj" placeholder="请输入最大力标距(mm)" />
        </el-form-item>
        <el-form-item label="最大力断后标距(mm)" prop="zuidldhbj">
          <el-input v-model="form.zuidldhbj" placeholder="请输入最大力断后标距(mm)" />
        </el-form-item>
        <el-form-item label="最大力总延伸率(%)" prop="zuidlzysl">
          <el-input v-model="form.zuidlzysl" placeholder="请输入最大力总延伸率(%)" />
        </el-form-item>
        <el-form-item label="强屈比" prop="qiangqb">
          <el-input v-model="form.qiangqb" placeholder="请输入强屈比" />
        </el-form-item>
        <el-form-item label="屈屈比" prop="qvqb">
          <el-input v-model="form.qvqb" placeholder="请输入屈屈比" />
        </el-form-item>
        <el-form-item label="断裂特征" prop="daunltz">
          <el-input v-model="form.daunltz" placeholder="请输入断裂特征" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listGcqfqdklqddhsclzdlzysljlbBsDetail,
  getGcqfqdklqddhsclzdlzysljlbBsDetail,
  delGcqfqdklqddhsclzdlzysljlbBsDetail,
  addGcqfqdklqddhsclzdlzysljlbBsDetail,
  updateGcqfqdklqddhsclzdlzysljlbBsDetail
} from "@/api/report_gc/gcqfqdklqddhsclzdlzysljlbBsDetail";

export default {
  name: "GcqfqdklqddhsclzdlzysljlbBsDetail",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情表格数据
      gcqfqdklqddhsclzdlzysljlbBsDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        excelId: undefined,
        gongczj: undefined,
        gongcjmj: undefined,
        qvfhz: undefined,
        qvfqd: undefined,
        jixhz: undefined,
        kanglqd: undefined,
        yuanszb: undefined,
        duanhbj: undefined,
        duanhscl: undefined,
        zuidlbj: undefined,
        zuidldhbj: undefined,
        zuidlzysl: undefined,
        qiangqb: undefined,
        qvqb: undefined,
        daunltz: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "不能为空", trigger: "blur" }],
        excelId: [{ required: true, message: "主表id不能为空", trigger: "blur" }],
        gongczj: [{ required: true, message: "公称直径(mm)不能为空", trigger: "blur" }],
        gongcjmj: [{ required: true, message: "公称截面积(mm²)不能为空", trigger: "blur" }],
        qvfhz: [{ required: true, message: "屈服荷载(kN)不能为空", trigger: "blur" }],
        qvfqd: [{ required: true, message: "屈服强度(MPa)不能为空", trigger: "blur" }],
        jixhz: [{ required: true, message: "极限荷载(kN)不能为空", trigger: "blur" }],
        kanglqd: [{ required: true, message: "抗拉强度(MPa)不能为空", trigger: "blur" }],
        yuanszb: [{ required: true, message: "原始标距(mm)不能为空", trigger: "blur" }],
        duanhbj: [{ required: true, message: "断后标距(mm)不能为空", trigger: "blur" }],
        duanhscl: [{ required: true, message: "断后伸长率(%)不能为空", trigger: "blur" }],
        zuidlbj: [{ required: true, message: "最大力标距(mm)不能为空", trigger: "blur" }],
        zuidldhbj: [{ required: true, message: "最大力断后标距(mm)不能为空", trigger: "blur" }],
        zuidlzysl: [{ required: true, message: "最大力总延伸率(%)不能为空", trigger: "blur" }],
        qiangqb: [{ required: true, message: "强屈比不能为空", trigger: "blur" }],
        qvqb: [{ required: true, message: "屈屈比不能为空", trigger: "blur" }],
        daunltz: [{ required: true, message: "断裂特征不能为空", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情列表 */
    getList() {
      this.loading = true;
      listGcqfqdklqddhsclzdlzysljlbBsDetail(this.queryParams).then((response) => {
        this.gcqfqdklqddhsclzdlzysljlbBsDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        excelId: undefined,
        gongczj: undefined,
        gongcjmj: undefined,
        qvfhz: undefined,
        qvfqd: undefined,
        jixhz: undefined,
        kanglqd: undefined,
        yuanszb: undefined,
        duanhbj: undefined,
        duanhscl: undefined,
        zuidlbj: undefined,
        zuidldhbj: undefined,
        zuidlzysl: undefined,
        qiangqb: undefined,
        qvqb: undefined,
        daunltz: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getGcqfqdklqddhsclzdlzysljlbBsDetail(id).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateGcqfqdklqddhsclzdlzysljlbBsDetail(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addGcqfqdklqddhsclzdlzysljlbBsDetail(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除钢材屈服强度、抗拉强度、断后伸长率、最大力总延伸率试验检测记录详情编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delGcqfqdklqddhsclzdlzysljlbBsDetail(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report_gc/gcqfqdklqddhsclzdlzysljlbBsDetail/export",
        {
          ...this.queryParams
        },
        `gcqfqdklqddhsclzdlzysljlbBsDetail_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
